import threading

from common import constants
from common.logger_factory import Log
from config import configuration
from config.config_handler import ConfigFileChangeHandler
from config.dynamic_configuration import ConfigurationFactory
from service.heartbeat_service import HeartbeatServer


def init():
    ConfigurationFactory.get_configuration()
    if constants.AUTOMATIC_LISTENER_ENABLED:
        ConfigFileChangeHandler.start_file_monitor()


if __name__ == "__main__":
    init()
    Log.console().info("^_^心跳服务中心启动！")
    server = HeartbeatServer(configuration.SERVER_HOST, configuration.SERVER_PORT)
    # 定期心跳检查
    threading.Thread(target=server.check_heartbeats).start()
    # 启动心跳服务
    server.start()
